﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Configuration;

namespace SiteParser.Core.Configuration
{
	public class ParserConfigSection : SerializableConfigurationSection
	{
		private static ParserConfigSection instance;
		private const string PARSER_CONFIG_SECTION_NAME = "ParserConfiguration";

		private ParserConfigSection() { }

		#region Singleton

		static ParserConfigSection() {
			instance = (ParserConfigSection)ConfigurationSourceFactory.Create().GetSection(PARSER_CONFIG_SECTION_NAME);
			if (instance == null) {
				throw new ConfigurationErrorsException(String.Format("Configuration section '{0}' is not defined.", PARSER_CONFIG_SECTION_NAME));
			}
		}

		public static ParserConfigSection Instance {
			get { return instance; }
		}

		#endregion Singleton

		private const string PARSER_CONFIG_FILE_PROPERTY_NAME = "parserConfigFilePath";
		[ConfigurationProperty(PARSER_CONFIG_FILE_PROPERTY_NAME, IsRequired = false)]
		public string ConfigFile {
			get { return (string)this[PARSER_CONFIG_FILE_PROPERTY_NAME]; }
		}

		private const string CACHING_CONFIG_PROPERTY_NAME = "CachingConfiguration";
		[ConfigurationProperty(CACHING_CONFIG_PROPERTY_NAME, IsRequired = true)]
		public CachingConfiguration CacheConfig {
			get { return (CachingConfiguration)this[CACHING_CONFIG_PROPERTY_NAME]; }
		}

		private const string RESOURCES_CONFIG_PROPERTY_NAME = "ResourcesConfiguration";
		[ConfigurationProperty(RESOURCES_CONFIG_PROPERTY_NAME, IsRequired = true)]
		public ResourcesConfiguration ResourcesConfig {
			get { return (ResourcesConfiguration)this[RESOURCES_CONFIG_PROPERTY_NAME]; }
		}

		private const string FORMATTER_CONFIGURATION_PROPERTY_NAME = "FormattersConfiguration";
		[ConfigurationProperty(FORMATTER_CONFIGURATION_PROPERTY_NAME, IsRequired = false)]
		public FormattersConfiguration FormattersConfig {
			get { return (FormattersConfiguration)this[FORMATTER_CONFIGURATION_PROPERTY_NAME]; }
		}
	}
}
